package com.sk.cardeal.act.home.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;
import com.dyhdyh.widget.loading.dialog.LoadingDialog;
import com.sk.cardeal.R;
import com.sk.cardeal.base.BaseActivity;
import com.sk.cardeal.callback.HandleDataCallBack;
import com.sk.cardeal.entity.CustomDetails;
import com.sk.cardeal.entity.Parts;
import com.sk.cardeal.utils.AppApi;
import com.sk.cardeal.utils.HttpAddress;
import com.sk.cardeal.utils.MyUtils;
import com.sk.cardeal.view.ExpandLayout;
import com.sk.cardeal.view.LineMenuView;
import com.sk.cardeal.view.TitleView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by sk on 2018/2/1.
 */

public class CustomDetailsActivity extends BaseActivity implements HandleDataCallBack {


    @BindView(R.id.title_view)
    TitleView titleView;
    @BindView(R.id.scan)
    ImageView scan;
    @BindView(R.id.tv_up_load)
    TextView tvUpLoad;
    @BindView(R.id.xs_image)
    ImageView xsImage;
    @BindView(R.id.ed_in_put)
    TextView edInPut;
    @BindView(R.id.ed_car_num)
    TextView edCarNum;
    @BindView(R.id.next)
    ImageView next;
    @BindView(R.id.car_loc)
    TextView carLoc;
    @BindView(R.id.car_type)
    LineMenuView carType;
    @BindView(R.id.car_model_type)
    LineMenuView carModelType;
    @BindView(R.id.vehicle_code)
    TextView vehicleCode;
    @BindView(R.id.engine_number)
    TextView engineNumber;
    @BindView(R.id.use_type)
    TextView useType;
    @BindView(R.id.validity_date)
    LineMenuView validityDate;
    @BindView(R.id.contact_phone)
    TextView contactPhone;
    @BindView(R.id.custom_detail_ll)
    RelativeLayout customDetailLl;
    @BindView(R.id.edit_sex)
    TextView editSex;
    @BindView(R.id.birth_data)
    LineMenuView birthData;
    @BindView(R.id.edit_location)
    TextView editLocation;
    @BindView(R.id.id_code)
    TextView idCode;
    @BindView(R.id.ed_work_address)
    TextView edWorkAddress;
    @BindView(R.id.custom_expand)
    ExpandLayout customExpand;
    @BindView(R.id.car_details_ll)
    RelativeLayout carDetailsLl;
    @BindView(R.id.scan_jiashi)
    ImageView scanJiashi;
    @BindView(R.id.upload_jiashi)
    TextView uploadJiashi;
    @BindView(R.id.js_image)
    ImageView jsImage;
    @BindView(R.id.allow_car)
    TextView allowCar;
    @BindView(R.id.get_date)
    TextView getDate;
    @BindView(R.id.start_date)
    TextView startDate;
    @BindView(R.id.end_date)
    TextView endDate;
    @BindView(R.id.car_color)
    TextView carColor;
    @BindView(R.id.reach_date)
    LineMenuView reachDate;
    @BindView(R.id.inspection_reach_date)
    LineMenuView inspectionReachDate;
    @BindView(R.id.ed_com1)
    TextView edCom1;
    @BindView(R.id.insurance_reach_date)
    LineMenuView insuranceReachDate;
    @BindView(R.id.ed_com2)
    TextView edCom2;
    @BindView(R.id.car_expand)
    ExpandLayout carExpand;

    private String id;
    private LoadingDialog loadingDialog;

    @Override
    protected int getContentView() {
        return R.layout.activity_custom_details;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        titleView.setMyCallBack(this);
        id = getIntent().getStringExtra("id");
        loadingDialog = MyUtils.getLoadingDialog(mContext, false);
        loadingDialog.show();
        AppApi.customDetails(id, "", this, 0, this);
    }

    @Override
    public void handlerSuccessData(String result, int tag) {

        loadingDialog.cancelDialog();
        CustomDetails customDetails = JSON.parseObject(result, CustomDetails.class);
        if (customDetails.getReturnObject().getBaseCustomerCar().getLicensePic() != null && customDetails.getReturnObject().getBaseCustomerCar().getLicensePic().length() > 0) {
            Glide.with(mContext).load(HttpAddress.ossPath + customDetails.getReturnObject().getBaseCustomerCar().getLicensePic()).into(xsImage);
        } else {
            tvUpLoad.setText("暂未上传");
        }
        if (customDetails.getReturnObject().getBaseCustomerCertificates().getDriverPic() != null && customDetails.getReturnObject().getBaseCustomerCertificates().getDriverPic().length() > 0) {
            Glide.with(mContext).load(HttpAddress.ossPath + customDetails.getReturnObject().getBaseCustomerCertificates().getDriverPic()).into(jsImage);
        } else {
            uploadJiashi.setText("暂未上传");
        }

        edInPut.setText(customDetails.getReturnObject().getPersonName());
        carLoc.setText(customDetails.getReturnObject().getBaseCustomerCar().getPlateNumber().substring(0, 1));
        edCarNum.setText(customDetails.getReturnObject().getBaseCustomerCar().getPlateNumber().substring(1, 7));

        if (customDetails.getReturnObject().getSex() == 1) {
            editSex.setText("女");
        } else if (customDetails.getReturnObject().getSex() == 0) {
            editSex.setText("男");
        }

        startDate.setText(customDetails.getReturnObject().getBaseCustomerCertificates().getStart_time());
        allowCar.setText(customDetails.getReturnObject().getBaseCustomerCertificates().getQuasi_driving());
        getDate.setText(customDetails.getReturnObject().getBaseCustomerCertificates().getGetTime());
        endDate.setText(customDetails.getReturnObject().getBaseCustomerCertificates().getYears());


        carColor.setText(customDetails.getReturnObject().getBaseCustomerCar().getColor());

        useType.setText(customDetails.getReturnObject().getBaseCustomerCar().getUserNature());

        vehicleCode.setText(customDetails.getReturnObject().getBaseCustomerCar().getVin());

        engineNumber.setText(customDetails.getReturnObject().getBaseCustomerCar().getEngineNo());

        idCode.setText(customDetails.getReturnObject().getCardNumber());

        carType.setHint(customDetails.getReturnObject().getBaseCustomerCar().getCarTypeName());
        carType.setHintColor(Color.parseColor("#232323"));

        carModelType.setHint(customDetails.getReturnObject().getBaseCustomerCar().getBrandModelName());
        carModelType.setHintColor(Color.parseColor("#232323"));

        editLocation.setText(customDetails.getReturnObject().getAddress() == null ? "" : customDetails.getReturnObject().getAddress());

        edWorkAddress.setText(customDetails.getReturnObject().getJob() == null ? "" : customDetails.getReturnObject().getJob());

        edCom1.setText(customDetails.getReturnObject().getBaseCustomerCar().getInsuranceCompany() == null ? "" : customDetails.getReturnObject().getBaseCustomerCar().getInsuranceCompany());
        edCom2.setText(customDetails.getReturnObject().getBaseCustomerCar().getSaliCompany() == null ? "" : customDetails.getReturnObject().getBaseCustomerCar().getSaliCompany());

        validityDate.setHint(customDetails.getReturnObject().getDlendTime()==null?"":customDetails.getReturnObject().getDlendTime());
        validityDate.setHintColor(Color.parseColor("#232323"));

        birthData.setHint(customDetails.getReturnObject().getBirthday()==null?"":customDetails.getReturnObject().getBirthday());
        birthData.setHintColor(Color.parseColor("#232323"));

        insuranceReachDate.setHint(customDetails.getReturnObject().getBaseCustomerCar().getSaliOutDate()==null?"":customDetails.getReturnObject().getBaseCustomerCar().getSaliOutDate());
        insuranceReachDate.setHintColor(Color.parseColor("#232323"));

        inspectionReachDate.setHint(customDetails.getReturnObject().getBaseCustomerCar().getInsuranceOutDate()==null?"":customDetails.getReturnObject().getBaseCustomerCar().getInsuranceOutDate());
        inspectionReachDate.setHintColor(Color.parseColor("#232323"));

        reachDate.setHint(customDetails.getReturnObject().getBaseCustomerCar().getAnnualInspectionDate()==null?"":customDetails.getReturnObject().getBaseCustomerCar().getAnnualInspectionDate());
        reachDate.setHintColor(Color.parseColor("#232323"));

        contactPhone.setText(customDetails.getReturnObject().getTelephone());

    }

    @Override
    public void handlerFailData(String failString, int tag) {
        loadingDialog.cancelDialog();
    }

    @Override
    public void handleErrorData(String error, int tag) {
        loadingDialog.cancelDialog();
    }

    @Override
    public void clickTitle(int i) {
        super.clickTitle(i);
        switch (i) {
            case 1:
                finish();
                break;
            case 2:
                break;
            case 3:
                break;
        }
    }
}
